#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char const *argv[])
{
    int fd = open("love3.txt",O_RDONLY);
    if(fd == -1){
        perror("错误111");
        return -1;
    }

    int fd2 = open("love4.txt",O_WRONLY|O_CREAT|O_APPEND,0664);
    if (fd2 == -1)
    {
        perror("错误222");
        close(fd);
        return -1;
    }
 
char buff[1024];
ssize_t love_len = 0;
while((love_len = read(fd,buff,sizeof(buff)))>0){

    write(fd2,buff,love_len);
    write(STDOUT_FILENO,buff,love_len);
}

if (love_len==-1)
{
    perror("错误333");
    close(fd);
    close(fd2);
    return -1;
}

    close(fd);
    close(fd2);
    
    return 0;
}
